class Solution(object):
    def removeOnes(self, grid):
        m = len(grid)
        n = len(grid[0])
        s = set()
        for i in range(m):
            t = grid[i]
            if t[0] == 1:
                t = [1 - num for num in t]
            if s:
                if tuple(t) not in s:
                    return False
            else:
                s.add(tuple(t))
        return True